<!DOCTYPE html>
<html>
<head>
	<title>浏览器sessionStorage存储</title>
</head>
<body>
	<h1>浏览器sessionStorage存储</h1>
	<button onclick="saveData()">存储</button>
	<button onclick="getData()">获取</button>
	<button onclick="removeData()">删除</button>
	<button onclick="clearData()">清空</button>
    <script>
        // 存储
        function saveData() {
            const person = {'name':'张三', 'age':25}
            sessionStorage.setItem('msg', 'hello world');
            sessionStorage.setItem('msg2', 'sessionStorage');
            sessionStorage.setItem('person', JSON.stringify(person));
            sessionStorage.setItem('num', 123);
        }
        // 获取
        function getData() {
            const person = {'name':'张三', 'age':25}
            console.log(sessionStorage.getItem('msg'));
            console.log(sessionStorage.getItem('msg2'));
            console.log(JSON.parse(sessionStorage.getItem('person')));
            console.log(sessionStorage.getItem('num'));
        }
        // 移除
        function removeData() {
            sessionStorage.removeItem('msg');
        }
        // 清空
        function clearData() {
            sessionStorage.clear();
        }
    </script>
</body>
</html>